package com.example.administrator.ksf_zty.util;

import android.app.Activity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.administrator.ksf_zty.R;


public class TitleUtils {
    private static RelativeLayout tileLayout;
    /**
     * 只有中间文字可见
     * @param titleLayout include布局id
     * @param title 标题名字
     */
    public static void setTitle(Activity view, int titleLayout, String title){
        //设置标题栏
        tileLayout = (RelativeLayout) view.findViewById(titleLayout);
        ((TextView) tileLayout.findViewById(R.id.title)).setText(title);

    }
    /**
     * 给标题栏设置属性  显示左中
     * @param titleLayout include布局id
     * @param title 标题名字
     * @param click  监听类
     */
    public static void setTitle(Activity view, int titleLayout, String title, View.OnClickListener click){
        //设置标题栏
        setTitle(view,titleLayout,title);
        ImageButton button = (ImageButton) tileLayout.findViewById(R.id.back);
        button.setVisibility(View.VISIBLE);
        button.setOnClickListener(click);
    }
    /**
     * 给标题栏设置属性  显示右中
     * @param titleLayout include布局id
     * @param title 标题名字
     * @param click  监听类
     */
    public static void setTitle2(Activity view, int titleLayout, String title, String right, View.OnClickListener click){
        //设置标题栏
        setTitle(view,titleLayout,title);
        //设置右边
        ImageButton button = (ImageButton) tileLayout.findViewById(R.id.back);
        button.setVisibility(View.VISIBLE);
//        button.setText(right);
        button.setOnClickListener(click);
    }
    /**
     * 给标题栏设置属性  显示左中右
     * @param titleLayout include布局id
     * @param title 标题名字
     * @param click  监听类
     */
    public static void setTitle(Activity view, int titleLayout, String title, View.OnClickListener click, String right, Boolean isLeft){
        //设置标题栏
        if(isLeft){
            setTitle(view,titleLayout,title,click);
        }else{
            setTitle(view,titleLayout,title);
        }
        //设置右边
        Button button = (Button) tileLayout.findViewById(R.id.titleButton);
        if (!TextUtils.isEmpty(right)) {
            button.setVisibility(View.VISIBLE);
            button.setText(right);
            button.setOnClickListener(click);
        }
    }
}
